<template>
  <div>
    <!-- <dv-loading v-if="dvLoading" class="loading-class">{{loadingText}}</dv-loading> -->
    <div class="container1">
      <div class="common-title-flex">
        <div class="common-title-div"></div>
        <div class="common-title-text">用户查询条件</div>
      </div>
      <el-form
        ref="searchObj"
        :inline="true"
        :model="searchObj"
        size="mini"
        label-width="120px"
        style="margin-bottom: -10px; margin-top: 10px"
      >
        <el-form-item label="用户名称">
          <el-input
            v-model="searchObj.nickName"
            placeholder="请输入用户名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="角色名称">
          <el-input
            v-model="searchObj.roleName"
            placeholder="请输入角色名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="创建人">
          <el-input
            v-model="searchObj.operateNick"
            placeholder="请输入创建人"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="小程序用户">
          <el-input
            v-model="searchObj.name"
            placeholder="请输入小程序用户"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="小程序ID">
          <el-input
            v-model="searchObj.openId"
            placeholder="请输入小程序ID"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="用户电话">
          <el-input
            v-model="searchObj.phone"
            placeholder="请输入用户电话"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="公司组织编码">
          <el-input
            v-model="searchObj.orgCode"
            placeholder="请输入公司组织编码"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="公司名称">
          <el-input
            v-model="searchObj.companyName"
            placeholder="请输入公司名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select
            v-model="searchObj.status"
            placeholder="请选择状态"
            style="width: 100%"
          >
            <el-option
              v-for="item in statusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="margin-left: 2rem">
          <el-button type="primary" icon="el-icon-search" @click="query"
            >查询</el-button
          >
          <el-button @click="reset" icon="el-icon-refresh">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="container" style="margin-top: 1rem">
      <div class="common-list-class">
        <div style="display: flex">
          <div class="common-title-div"></div>
          <div class="common-title-text">用户查询列表</div>
        </div>
        <el-button
          type="primary"
          style="height: 32px"
          icon="el-icon-circle-plus-outline"
          @click="addPolice"
          >添加</el-button
        >
      </div>
      <!-- 查询列表 -->
      <el-table
        :data="tableData"
        :row-style="rowStyle"
        :header-cell-style="tableHeaderColor"
        size="mini"
        style="width: 100%; margin-top: 10px; margin-bottom: 10px"
        max-height="550"
        border
      >
        <el-table-column
          prop="nickName"
          label="用户名称"
          width="150"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="accountName"
          label="账户名称"
          width="150"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="roleName"
          label="角色名称"
          width="150"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="小程序用户"
          width="150"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="openId"
          label="小程序ID"
          width="150"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="phone"
          label="用户电话"
          width="150"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="orgCode"
          label="公司组织编码"
          width="150"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="companyName"
          label="公司名称"
          width="150"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="loginNum"
          label="登录次数"
          width="100"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          width="100"
          show-overflow-tooltip
          align="center"
        >
          <template slot-scope="scope">
            {{ statusObj[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="loginTime"
          label="登录时间"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="operateNick"
          label="创建人"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="400" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              v-if="scope.row.accountName !== 'admin'"
              size="mini"
              icon="el-icon-edit"
              @click="editClick(scope.row)"
              >修改</el-button
            >
            <!-- <el-button type="primary" size="mini" icon="el-icon-tickets" @click="detailsClick(scope.row)">详情</el-button> -->
            <el-button
              type="success"
              size="mini"
              icon="el-icon-video-play"
              v-if="
                scope.row.status == '0' && scope.row.accountName !== 'admin'
              "
              @click="startClick(scope.row)"
              >启动</el-button
            >
            <el-button
              type="info"
              size="mini"
              icon="el-icon-remove"
              v-if="
                scope.row.status == '1' && scope.row.accountName !== 'admin'
              "
              @click="forbidClick(scope.row)"
              >停用</el-button
            >
            <el-button
              type="danger"
              v-if="scope.row.accountName !== 'admin' && !scope.row.openId"
              size="mini"
              icon="el-icon-delete"
              @click="deleteClick(scope.row)"
              >删除</el-button
            >
            <el-button
              type="primary"
              v-if="roleCode == 'systemAdmin'"
              size="mini"
              icon="el-icon-refresh"
              @click="refreshClick(scope.row)"
              >重置</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-row type="flex" justify="end">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-row>
    </div>
    <!-- 新增警员 和修改警员-->
    <el-dialog
      :title="isEditTitle"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="newaddFlag"
      width="50%"
      :before-close="cancel"
      center
    >
      <div slot="title" class="header-title">
        <div class="header-title-div"></div>
        <div class="header-title-text">{{ isEditTitle }}</div>
      </div>
      <el-form
        ref="inputObj"
        :model="inputObj"
        label-width="120px"
        :rules="rules"
      >
        <el-form-item
          label="账户名称"
          prop="account"
          v-if="isEditTitle == '新增用户'"
        >
          <el-tooltip
            class="item"
            effect="dark"
            content="账号格式：大小写字母或数字"
            placement="top-start"
          >
            <el-input
              v-model="inputObj.account"
              placeholder="请输入账户名称"
              clearable
            ></el-input>
          </el-tooltip>
        </el-form-item>
        <el-form-item
          label="账户密码"
          prop="userpwd"
          v-if="isEditTitle == '新增用户'"
        >
          <el-tooltip
            class="item"
            effect="dark"
            content="密码格式：大小写字母或数字"
            placement="top-start"
          >
            <el-input
              v-model="inputObj.userpwd"
              placeholder="请输入账户密码"
              clearable
              show-password
            ></el-input>
          </el-tooltip>
        </el-form-item>
        <el-form-item label="用户名称" prop="username">
          <el-input
            v-model="inputObj.username"
            @input="onInput()"
            placeholder="请输入用户名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="角色名称" prop="bindRole">
          <el-select
            v-model="inputObj.bindRole"
            filterable
            placeholder="请选择绑定角色"
            @change="bindRoleChange"
            style="width: 100%"
          >
            <el-option
              v-for="item in bindRoleList"
              :key="item.id"
              :label="item.roleName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          prop="girdId"
          label="所属网格"
          v-if="inputObj.bindRole == 4 || inputObj.bindRole == 5"
        >
          <el-select
            v-model="inputObj.girdId"
            placeholder="请选择所属网格"
            style="width: 100%"
            @change="girdIdChange"
          >
            <el-option
              v-for="item in selfAreaList"
              :key="item.value"
              :label="item.gridName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公司名称" v-if="showFlag">
          <el-select
            v-model="inputObj.company"
            filterable
            placeholder="请选择公司名称"
            style="width: 100%"
            @change="companyChange"
          >
            <el-option
              v-for="item in companyList"
              :key="item.orgCode"
              :label="item.companyName"
              :value="item.orgCode"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公司编码" v-if="showFlag">
          <el-input v-model="inputObj.companyCode" disabled></el-input>
        </el-form-item>
        <el-form-item
          prop="descOrgCode"
          class="required-content-red"
          label="服务企业"
          v-if="inputObj.bindRole == 14"
        >
          <el-select
            v-model="inputObj.descOrgCode"
            placeholder="请选择服务企业"
            style="width: 100%"
            @change="descOrgCodeChange"
          >
            <el-option
              v-for="item in bindingList"
              :key="item.ORG_CODE"
              :label="item.COMPANY_NAME"
              :value="item.ORG_CODE"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">提 交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 警员详情 -->
    <el-dialog
      title="用户详情"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="detailsFlag"
      width="40%"
      :before-close="detailsClose"
      center
    >
      <div slot="title" class="header-title">
        <div class="header-title-div"></div>
        <div class="header-title-text">用户详情</div>
      </div>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">用户名称</el-col>
        <el-col :span="15" class="grey-class">{{ detailsObj.username }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">绑定角色</el-col>
        <el-col :span="15" class="grey-class">{{ detailsObj.bindRole }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">状态</el-col>
        <el-col :span="15" class="grey-class">{{ detailsObj.status }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">创建人</el-col>
        <el-col :span="15" class="grey-class">{{ detailsObj.person }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">创建时间</el-col>
        <el-col :span="15" class="grey-class">{{ detailsObj.time }}</el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="danger" @click="detailsClose">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixin/mixin.js";
export default {
  name: "usermanager",
  mixins: [mixin],
  data() {
    const self = this;
    return {
      uploadHeader: {
        token: "1244567788",
      },
      selfAreaList: [],
      uploadUrl: "https://jsonplaceholder.typicode.com/posts/",
      rules: {
        bindRole: [
          { required: true, message: "请选择绑定角色", trigger: "change" },
        ],
        girdId: [
          { required: true, message: "请选择所属网格", trigger: "change" },
        ],
        account: [
          { required: true, message: "请输入账号名称", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              if (!/^[0-9a-zA-Z]+$/.test(value.trim())) {
                callback(new Error("账号名称格式错误！"));
              } else {
                self
                  .$axios({
                    method: "get",
                    url: `/system/validateAccountExist/${value.trim()}`,
                    headers: {
                      Authorization: this.requestToken,
                    },
                  })
                  .then((res) => {
                    console.log(res.data);
                    if (res.data.code == "20000" && res.data.data) {
                      callback();
                    } else {
                      self.inputObj.username = "";
                      callback(new Error("账号已存在！请重新输入！"));
                    }
                  })
                  .catch((err) => {
                    callback(new Error(err));
                  });
              }
            },
            trigger: "blur",
          },
        ],
        username: [
          { required: true, message: "请输入用户名称", trigger: "blur" },
        ],
        userpwd: [
          { required: true, message: "请输入账号密码", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              if (!/^[0-9a-zA-Z]+$/.test(value.trim())) {
                callback(new Error("密码格式错误！"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
      },
      detailsObj: {
        username: "",
        bindRole: "",
        person: "",
        time: "",
        status: "",
        person: "",
      },
      inputObj: {
        account: "",
        username: "",
        userpwd: "",
        bindRole: "",
        girdId: "",
      },
      companyList: [],
      statusObj: {
        0: "已停用",
        1: "已启用",
      },
      detailsFlag: false,
      isEditTitle: "",
      newaddFlag: false,
      pageSizes: [10, 15, 50, 100],
      pagesize: 10,
      total: 10,
      currentPage: 1,
      tableData: [],
      searchObj: {
        companyName: "",
        orgCode: "",
        status: "",
        phone: "",
        openId: "",
        name: "",
        operateNick: "",
        roleName: "",
        nickName: "",
      },
      statusList: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "0",
          label: "已停用",
        },
        {
          value: "1",
          label: "已启用",
        },
      ],
      bindRoleList: [],
      serialId: "",
      typeCode: "",
      showFlag: false,
      bindingList: [],
      userinfo: {},
    };
  },
  created() {
    let userinfo = JSON.parse(localStorage.getItem("userinfo"));
    this.userinfo = userinfo;
    this.typeCode = userinfo.typeCode;
    if (this.typeCode == "business" || this.typeCode == "labour") {
      this.initCompanyList(this.typeCode);
    }
    this.initBindRoleList();
    this.query();
  },
  methods: {
    onInput() {
      this.$forceUpdate();
    },
    descOrgCodeChange() {
      this.$forceUpdate();
    },
    initSelfAreaList() {
      let params = {};
      this.$axios({
        method: "get",
        url: `/police/queryGirdInfo`,
        headers: {
          Authorization: this.requestToken,
        },
        data: params,
        params: params,
      })
        .then((res) => {
          if (res.data.code == "20000") {
            this.selfAreaList = res.data.data;
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      return "background-color:#f5f5f5;color:#626262;";
    },
    rowStyle({ row, rowIndex }) {
      let style1 = {};
      let style2 = {};
      if (rowIndex % 2 == 0) {
        style1.background = "#ffffff";
        return style1;
      } else {
        style2.background = "#f5f5f5";
        return style2;
      }
    },
    girdIdChange() {
      this.$forceUpdate();
    },
    companyChange(value) {
      if (this.isEditTitle == "新增用户") {
        let val = this.inputObj.company;
        this.initreviewList(val);
      } else {
        this.initreviewupdateList();
      }
      let self = this;
      let params = {
        orgCode: value,
        roleId: this.inputObj.bindRole,
      };
      this.showLoading();
      self
        .$axios({
          method: "get",
          url: `/system/validateUser`,
          headers: {
            Authorization: this.requestToken,
          },
          params: params,
          data: params,
        })
        .then((res) => {
          this.hideLoading();
          if (res.data.code == "20000") {
            if (!res.data.data) {
              this.$message.error(res.data.message);
              this.inputObj.company = "";
              this.inputObj.companyCode = "";
              this.$forceUpdate();
            } else {
              this.inputObj.companyCode = value;
              this.$forceUpdate();
            }
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          this.hideLoading();
          this.$message.error(err);
        });
    },
    initreviewupdateList() {
      let self = this;
      self.showLoading();
      let params = {
        labourCode: self.inputObj.company,
      };
      self
        .$axios({
          method: "get",
          url: `/site/queryAllCompany`,
          headers: {
            Authorization: self.requestToken,
          },
          params: params,
          data: params,
        })
        .then((res) => {
          self.hideLoading();
          if (res.data.code == "20000") {
            let dataList = res.data.data;
            let data = [];
            dataList.forEach((item) => {
              data.push({
                COMPANY_NAME: item.companyName,
                ORG_CODE: item.orgCode,
              });
            });
            self.bindingList = data;
          } else {
            self.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          self.hideLoading();
          self.$message.error(err);
        });
    },
    bindRoleChange(value) {
      this.$forceUpdate();
      console.log("value-----", value);
      if (value == 14 && this.userinfo.roleCode == "labourBusinessManage") {
        let val = this.userinfo.orgCode;
        this.initreviewList(val);
      }
      let obj = this.bindRoleList.find((item) => {
        return item.id == value;
      });
      let name = obj.roleName;
      this.inputObj.companyCode = "";
      this.inputObj.company = "";
      if (name.startsWith("劳务公司") && this.typeCode == "system") {
        this.showFlag = true;
        this.initCompanyList("labour");
      } else if (name.startsWith("企业") && this.typeCode == "system") {
        this.showFlag = true;
        this.initCompanyList("business");
      } else {
        this.showFlag = false;
      }
    },
    // 初始化劳务公司或企业
    initCompanyList(typeCode) {
      let self = this;
      let params = {
        typeCode: typeCode,
      };
      this.$axios({
        method: "get",
        url: `system/queryCompanyListByCondition`,
        headers: {
          Authorization: this.requestToken,
        },
        params: params,
      })
        .then((res) => {
          if (res.data.code == "20000") {
            this.companyList = res.data.data;
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    // 初始化角色列表
    initBindRoleList() {
      let self = this;
      let typeCode = self.typeCode;
      this.$axios({
        method: "get",
        url: `system/queryRoleListByTypeCode/${typeCode}`,
        headers: {
          Authorization: this.requestToken,
        },
      })
        .then((res) => {
          if (res.data.code == "20000") {
            this.bindRoleList = res.data.data;
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    // 新建确认和修改确认
    submit() {
      let self = this;
      this.$refs["inputObj"].validate((valid) => {
        if (valid) {
          if (self.isEditTitle == "新增用户") {
            if (self.showFlag) {
              if (!self.inputObj.company || !self.inputObj.company.length) {
                self.$message.error("请选择公司！");
                return;
              }
            }
            let companyName = "";
            console.log("self.inputObj.company---", self.inputObj.company);
            self.companyList.forEach((item) => {
              if (self.inputObj.company == item.orgCode) {
                companyName = item.companyName;
              }
            });
            // if(!self.inputObj.descOrgCode || !self.inputObj.descOrgCode.length){
            //     // self.$message.error('请选择服务企业！')
            //     return;
            // }
            let descCompanyName = "";
            self.bindingList.forEach((item) => {
              if (self.inputObj.descOrgCode == item.ORG_CODE) {
                descCompanyName = item.COMPANY_NAME;
              }
            });
            let params = {
              accountName: self.inputObj.account,
              password: self.inputObj.userpwd,
              nickName: self.inputObj.username,
              roleId: self.inputObj.bindRole,
              companyName: companyName,
              orgCode: self.inputObj.companyCode,
              girdId: self.inputObj.girdId,
              descOrgCode: self.inputObj.descOrgCode,
              descCompanyName: descCompanyName,
            };
            if (self.typeCode == "business" || self.typeCode == "labour") {
              params.companyName = self.userinfo.companyName;
              params.orgCode = self.userinfo.orgCode;
            }
            self.showLoading();
            self
              .$axios({
                method: "post",
                url: `system/addUser`,
                headers: {
                  Authorization: self.requestToken,
                },
                data: params,
                params: params,
              })
              .then((res) => {
                self.hideLoading();
                if (res.data.code == "20000") {
                  self.newaddFlag = false;
                  self.showFlag = false;
                  self.$message.success(res.data.message);
                  self.$refs["inputObj"].resetFields();
                  self.inputObj = {};

                  self.query();
                } else {
                  self.$message.error(res.data.message);
                }
              })
              .catch((err) => {
                self.hideLoading();
                self.$message.error(err);
              });
          } else {
            console.log("self.inputObj.company---", self.inputObj.company);
            let companyName = "";
            self.companyList.forEach((item) => {
              if (self.inputObj.company == item.orgCode) {
                companyName = item.companyName;
              }
            });
            // if(!self.inputObj.descOrgCode || !self.inputObj.descOrgCode.length){
            //     // self.$message.error('请选择服务企业！')
            //     return;
            // }
            let descCompanyName = "";
            self.bindingList.forEach((item) => {
              if (self.inputObj.descOrgCode == item.ORG_CODE) {
                descCompanyName = item.COMPANY_NAME;
              }
            });
            let params = {
              nickName: self.inputObj.username,
              roleId: self.inputObj.bindRole,
              companyName: companyName,
              orgCode: self.inputObj.companyCode,
              id: self.serialId,
              girdId: self.inputObj.girdId,
              descOrgCode: self.inputObj.descOrgCode,
              descCompanyName: descCompanyName,
            };
            if (self.typeCode == "business" || self.typeCode == "labour") {
              params.companyName = self.userinfo.companyName;
              params.orgCode = self.userinfo.orgCode;
            }
            self.showLoading();
            self
              .$axios({
                method: "post",
                url: `system/editUser`,
                headers: {
                  Authorization: self.requestToken,
                },
                data: params,
                params: params,
              })
              .then((res) => {
                self.hideLoading();
                if (res.data.code == "20000") {
                  self.newaddFlag = false;
                  self.showFlag = false;
                  self.$refs["inputObj"].resetFields();
                  self.inputObj = {};
                  self.$message.success("编辑成功！");
                  self.query();
                } else {
                  self.$message.error(res.data.message);
                }
              })
              .catch((err) => {
                self.hideLoading();
                self.$message.error(err);
              });
          }
        } else {
          return false;
        }
      });
    },
    // 取消点击
    cancel() {
      this.newaddFlag = false;
      this.inputObj = {
        account: "",
        username: "",
        userpwd: "",
        bindRole: "",
      };
      this.$refs["inputObj"].resetFields();
    },
    // 点击分页当前页多少数据
    handleSizeChange(val) {
      this.pagesize = val;
      this.query();
    },
    // 点击分页页数
    handleCurrentChange(val) {
      this.currentPage = val;
      this.query();
    },
    // 查询
    query() {
      let self = this;
      let params = {
        pageNumber: this.currentPage,
        pageSize: this.pagesize,
        status: this.searchObj.status,
        companyName: this.searchObj.companyName,
        orgCode: this.searchObj.orgCode,
        openId: this.searchObj.openId,
        phone: this.searchObj.phone,
        name: this.searchObj.name,
        operateNick: this.searchObj.operateNick,
        roleName: this.searchObj.roleName,
        nickName: this.searchObj.nickName,
      };
      self.showLoading();
      self
        .$axios({
          method: "post",
          url: `/system/queryUserByPage`,
          headers: {
            Authorization: self.requestToken,
          },
          data: params,
          params: params,
        })
        .then((res) => {
          self.hideLoading();
          if (res.data.code == "20000") {
            let responseData = res.data.data;
            self.tableData = responseData.list;
            self.total = responseData.total;
            self.pagesize = responseData.pageSize;
            self.currentPage = responseData.pageNum;
          } else {
            self.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          self.hideLoading();
          self.$message.error(err);
        });
    },
    //  重置
    reset() {
      this.searchObj = {
        companyName: "",
        orgCode: "",
        status: "",
        phone: "",
        openId: "",
        name: "",
        operateNick: "",
        roleName: "",
        nickName: "",
      };
      this.query();
    },
    // 重置密码
    refreshClick(row) {
      this.$confirm("请确认是否重置该用户密码?", "重置密码", {
        confirmButtonText: "是",
        cancelButtonText: "否",
      })
        .then(() => {
          this.showLoading();
          this.$axios({
            method: "get",
            url: `/index/resetPassword/${row.id}`,
            headers: {
              Authorization: this.requestToken,
            },
          })
            .then((res) => {
              this.hideLoading();
              if (res.data.code == "20000") {
                this.$message.success(res.data.message);
                this.query();
              } else {
                this.$message.error(res.data.message);
              }
            })
            .catch((err) => {
              this.hideLoading();
              this.$message.error(err);
            });
        })
        .catch(() => {
          console.log("取消重置密码");
        });
    },
    // 删除
    deleteClick(row) {
      this.$confirm("请确认是否删除该用户?", "删除", {
        confirmButtonText: "是",
        cancelButtonText: "否",
      })
        .then(() => {
          this.showLoading();
          this.$axios({
            method: "get",
            url: `/system/deleteUser/${row.id}`,
            headers: {
              Authorization: this.requestToken,
            },
          })
            .then((res) => {
              this.hideLoading();
              if (res.data.code == "20000") {
                this.$message.success("删除成功！");
                this.query();
              } else {
                this.$message.error(res.data.message);
              }
            })
            .catch((err) => {
              this.hideLoading();
              this.$message.error(err);
            });
        })
        .catch(() => {
          console.log("取消删除");
        });
    },
    // 点击启用
    startClick(row) {
      this.$confirm("请确认是否启用该用户?", "启用", {
        confirmButtonText: "是",
        cancelButtonText: "否",
      })
        .then(() => {
          this.showLoading();
          this.$axios({
            method: "get",
            url: `/system/enableOrDisableUser/${row.id}/1`,
            headers: {
              Authorization: this.requestToken,
            },
          })
            .then((res) => {
              this.hideLoading();
              if (res.data.code == "20000") {
                this.$message.success("启用成功！");
                this.query();
              } else {
                this.$message.error(res.data.message);
              }
            })
            .catch((err) => {
              this.hideLoading();
              this.$message.error(err);
            });
        })
        .catch(() => {
          console.log("取消启用");
        });
    },
    // 停用
    forbidClick(row) {
      this.$confirm("请确认是否停用该用户?", "停用", {
        confirmButtonText: "是",
        cancelButtonText: "否",
      })
        .then(() => {
          this.showLoading();
          this.$axios({
            method: "get",
            url: `/system/enableOrDisableUser/${row.id}/0`,
            headers: {
              Authorization: this.requestToken,
            },
          })
            .then((res) => {
              this.hideLoading();
              if (res.data.code == "20000") {
                this.$message.success("停用成功！");
                this.query();
              } else {
                this.$message.error(res.data.message);
              }
            })
            .catch((err) => {
              this.hideLoading();
              this.$message.error(err);
            });
        })
        .catch(() => {
          console.log("取消停用");
        });
    },
    // 新增
    addPolice() {
      this.newaddFlag = true;
      this.isEditTitle = "新增用户";
      this.initSelfAreaList();
    },
    initreviewList(val) {
      let self = this;
      self.showLoading();
      let params = {
        labourCode: val,
      };
      self
        .$axios({
          method: "get",
          url: `/site/queryInitAddLabourSite`,
          headers: {
            Authorization: self.requestToken,
          },
          params: params,
          data: params,
        })
        .then((res) => {
          self.hideLoading();
          if (res.data.code == "20000") {
            self.bindingList = res.data.data.businessInfos;
          } else {
            self.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          self.hideLoading();
          self.$message.error(err);
        });
    },
    // 详情
    detailsClick(row) {
      console.log(row);
      this.detailsFlag = true;
      this.detailsObj = {
        username: row.username,
        bindRole: row.bindRole,
        status: row.status == "1" ? "已启用" : "已停用",
        time: row.createTime,
        person: row.createName,
      };
    },
    // 详情关闭
    detailsClose() {
      this.detailsFlag = false;
    },
    // 修改
    editClick(row) {
      console.log(row);
      this.isEditTitle = "修改用户";
      let name = row.roleName;
      if (name.startsWith("劳务公司") && this.typeCode == "system") {
        this.showFlag = true;
        this.initCompanyList("labour");
        this.inputObj.company = row.orgCode;
        this.inputObj.companyCode = row.orgCode;
      } else if (name.startsWith("企业") && this.typeCode == "system") {
        this.showFlag = true;
        this.initCompanyList("business");
        this.inputObj.company = row.orgCode;
        this.inputObj.companyCode = row.orgCode;
      } else {
        this.showFlag = false;
        this.inputObj.company = row.orgCode;
        this.inputObj.companyCode = row.orgCode;
      }
      this.newaddFlag = true;
      this.serialId = row.id;
      this.initSelfAreaList();
      if (row.roleId == 14) {
        this.inputObj.company = row.orgCode;
        this.initreviewupdateList();
      }
      this.inputObj.descOrgCode = row.descOrgCode;
      this.inputObj.girdId = row.girdId;
      this.inputObj.username = row.nickName;
      this.inputObj.bindRole = row.roleId + "";
    },
  },
};
</script>
<style scoped>
/* .el-switch__core:after {
    content: "";
    position: absolute;
    top: 1px;
    left: 1px;
    border-radius: 100%;
    transition: all .3s;
    width: 16px;
    height: 16px;
    background-color: #fff;
  }
  .el-switch.is-checked .el-switch__core:after {
    left: 100%;
    margin-left: -17px;
  } */
.common-title-flex {
  display: flex;
}
.common-title-div {
  width: 3px;
  height: 16px;
  background-color: #368af7;
  margin-top: 2px;
}
.common-title-text {
  margin-left: 4px;
  font-size: 14px;
}
.common-list-class {
  display: flex;
  justify-content: space-between;
  margin-top: -10px;
}
.upload-file >>> .el-upload--text {
  border: none;
  width: 100px;
  height: 36px;
}
</style>